// Lang_22 [method references (instance)].nova // The application class. class MethodReferencesInstanceApp { // Application class's "main" function. public static void main( String[] args ) { // Create an instance of the example class. ExampleClass e = new ExampleClass( ); // Declare an instance method reference. String ( ExampleClass )( ) methodRef = ExampleClass.add; // Declare and initialize a generic method reference primitive. method m = methodRef; // Set the values of the example class's data members. e.x = 12; e.y = 3; // Call the instance method reference. Stream.writeLine( e.( methodRef )( ) ); // Declare an instance method reference. String ( Integer )( ) methodRef2 = Integer.toString; // Assign to a generic method reference primitive. m = methodRef2; // Call the instance method reference. Stream.writeLine( ( new Integer( e.x * e.y ) ).( methodRef2 )( ) ); } } // Example class with a static subtraction method. class ExampleClass { // Instance attributes. public int x; public int y; // Default constructor. public ExampleClass( ) { x = 100; y = 25; // Declare an instance method reference. String ( ExampleClass )( ) methodRef = add; // Call the instance method reference. Stream.writeLine( methodRef( ) ); } // Instance method to add two Integers and return a String result. public String add( ) { Stream.writeLine( "instance method \"add\" called." ); return Integer.toString( x + y ); } }